package com.zhiyou100.review.day013.test;

import java.util.Calendar;
import java.util.Scanner;

/**
 * @packageName: exercise
 * @className: com.zhiyou100.review.day013.test
 * @Description: TODO 练习
 * @author: yang
 * @date: 6/19/20
 */
public class Exercise {
    public static void main(String[] args) {
        System.out.println(Math.round(11.5));
        System.out.println(Math.round(-11.5));



        String username = "123";
        if (username.equals("zxx")) {
            // 建议 改为 "zxx".equals(username) , 否则容易发生 NullPointerException
        }
        ;


    }

    public static boolean isTest() {
        int x = 1;
        return x == 1 ? true : false;
        // 'x == 1 ? true : false' 可以简化为 'x == 1'
    }


    /**
     * @Description: TODO 猜时间的游戏
     * @name: guessTime
     * @param: []
     * @return: void
     * @date: 6/19/20 19:01
     * @author: yang
     */
    private static void guessTime() {
        Calendar instance = Calendar.getInstance();
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH) + 1;
        // 月份从 0 开始
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int hours = instance.get(Calendar.HOUR_OF_DAY);
        int minute = instance.get(Calendar.MINUTE);
        int second = instance.get(Calendar.SECOND);

        guessOneTime("请输入年", year);
        guessOneTime("请输入月", month);
        guessOneTime("请输入号", day);
        guessOneTime("请输入时", hours);
        guessOneTime("请输入分", minute);
        guessOneTime("请输入秒", second);

        String message = year + "-" + month + "-" + day + " " + hours + ":" + minute + ":" + second;
        System.out.println("恭喜你，猜对了，时间是" + message);

    }

    /**
     * @Description: TODO 猜传入的 number
     * @name: guessOneTime
     * @param: [message, number]
     * @return: void
     * @date: 6/19/20 18:56
     * @author: yang
     */
    public static void guessOneTime(String message, int number) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println(message);
            int m = scanner.nextInt();
            if (m == number) {
                System.out.println("恭喜你，猜对了！");
                return;
            }
            if (m > number) {
                System.out.println("大了");
            }
            if (m < number) {
                System.out.println("小了");
            }
        }
    }


}
